
<!--layer弹出层1-->
 <!-- nav -->

   <div  id ="fileChoose" style="display: none;">
    <nav ui-nav class="navi" ng-include="'src/app/program/contains_file.html'"></nav>
   </div>
    <!-- nav -->






  <div class="panel-body" ng-controller="fileChoosectrl">

         <p class="text-muted"><span class="label label-info">影视资源信息</span></p>    

  <div class="panel panel-default">

    <div>
   <div class="row">

 <div class="col-sm-12" >
 <div class="panel-heading">









<a href="javascript:void(0);" ng-click="goEdit();">
<button class="btn btn-default btn-sm"><i class="fa fa-edit fa-lg"></i>&nbsp;编辑</button></a>

<a href="javascript:void(0);" ng-click="goRemove();"><button class="btn btn-default btn-sm"><i class="fa fa-trash-o fa-lg"></i>&nbsp;删除</button></a>
<a class="btn btn-default btn-sm" ng-click="openFilePage();"><i class="fa fa-plus"></i>&nbsp;选择文件</a>

<button class="btn btn-default btn-sm " ng-click="goBack()"><i class="fa fa-mail-reply fa-lg"></i>&nbsp; 返回</button>


<!--隐藏域-->
<input type="hidden" id ="optIds" name="optIds">

</div>
 </div>


 </div>
      <table id="diversityTable" class="table table-striped m-b-none">
      </table>
    
    </div>

</div>
                
            </div>



<!--播放功能隐藏部分-->
       <!--    <div id ="ckplayer" style="display: none;">
              <nav ui-nav class="navi" ng-include="'src/app/play/player.html'"></nav>
          </div> -->
<!--播放功能隐藏部分-->






<!--  影视资源JS-->
<script type="text/javascript">

//angularjs总控制器
app.controller('fileChoosectrl', function($scope, $http,$state, $stateParams,$http,$window) {

//返回按钮：开始
$scope.$window = $window;
    $scope.goBack = function() {
      $window.history.back();
    };
//返回按钮：结束







   $scope.goEdit = function () {
  var optIds = $('#optIds').val();
     if(''==optIds){
    top.layer.msg('请至少选择一项', {icon: 6});
       return false;
  }
  if(optIds.indexOf(",") != -1){
    top.layer.msg('编辑只能选择一项', {icon: 6});
    return false;
  }
        $state.go('app.movie.deversityEdit', {infoId: optIds});
    };



//进入编辑页面
   $scope.goRemove = function () {
  var optIds = $('#optIds').val();
     if(''==optIds){
    top.layer.msg('请至少选择一项', {icon: 6});
       return false;
    }

    top.layer.confirm('您确定删除这些信息吗', function(index){

    var postInfoUrl = API_URL+"program_diversity";

    var optArrs = optIds.split(',');

    for(var i = 0;i< optArrs.length;i++ ){

         var infoUrl = API_URL+"program_diversity?query=delflag:0,Id:"+optArrs[i];

          var formData =  MY_ASYNC_AJAX(infoUrl)[0];
         
          formData.Delflag = "1";

     $.ajax({
         url : postInfoUrl+'/'+optArrs[i],
        type : 'put',
         data: JSON.stringify(formData),
       cache : false,
     success : function(data) {

      }
    });

    }
        var table = $('#diversityTable').DataTable();
         table.draw(false);
        top.layer.msg('删除成功');
  

  });

    
    };




  $scope.openFilePage=function(){
 
    top.layer.open({
        type: 1,
        title: '选择文件',
        shadeClose: false,
        anim: 1,
           shift: 4,
        shade: [0.5],
            fix: true,
        maxmin: true,
        move: true,
        area: ['1000px', '700px'],
        content: $('#fileChoose')
      });
   }





    var url = API_URL+"channel_info?query=delflag:0&limit=5&offset=0"    

    $http.get(url).success(function (response) {
    $scope.records = response ;

    });
   

});





function checkOne(){
  var optIds = '';
  $("input[name='ids']:checkbox:checked").each(function(){ 
      optIds+=$(this).val() +',';
       });
   if(''!=optIds){
        optIds = optIds.substring(0,optIds.length-1);
      }
$('#optIds').val(optIds);

  console.log($('#optIds').val());
}





//单条删除
  function goDelete(id){
      top.layer.confirm('您确定删除吗', function(index){
              var postInfoUrl = API_URL+"program_diversity";

          var infoUrl = API_URL+"program_diversity?query=delflag:0,Id:"+id;

          var formData =  MY_ASYNC_AJAX(infoUrl)[0];

         formData.Delflag = "0";
   $.ajax({
      url : postInfoUrl+'/'+id,
      type : 'put',
      data: JSON.stringify(formData),
      cache : false,
      success : function(data) {
        top.layer.msg('删除成功');

      $("#diversityTable").DataTable().ajax.reload().draw();
      }
    });



 top.layer.close(index);
      });
  }




function getProgramIdValue(){

  var programIdValue = window.location.href;

  programIdValue = programIdValue.substr(programIdValue.lastIndexOf('/') +1,programIdValue.length) ;

 return programIdValue ;

}

var programIdValue = getProgramIdValue();

 var diversityDtUrl =  API_URL+"program_diversity?query=delflag:0,programId:"+programIdValue;

function getDataSet(){
  var dataSet  =  MY_ASYNC_AJAX(diversityDtUrl);
  if(null==dataSet){
  dataSet = [];
  }
  return dataSet;
}


    $(document).ready(function(){


 //初始化dataTable
     var table =  $('#diversityTable').DataTable({
       
             ajax: {
                url: diversityDtUrl,
                dataSrc: ""
            },
         deferRender:true,
         Processing:true,
          buttons: [
        {
            extend: 'collection',
            text: 'Export',
            buttons: [ 'csv-flash', 'xls-flash', 'pdf-flash' ]
        }
    ],
            //默认最后一列（最后更新时间）降序排列
            order: [[3, "desc"]],
         
            //行创建完成后回调
            rowCallback: function (row, data, index) {
               
            },
                    aoColumns: [
                    { data : "Id",
                    title: "<input type='checkbox' id='allChecked' name='allChecked' />",
                  orderable: false , 
              render : function(data, type, full, meta) {
            return '<input type="checkbox" value="'+ data + '" name="ids" onclick="checkOne()"/>';
           }},
       
            { data: "ProgramId" ,title: "节目ID"},
            { data: "DiversityId", title: "分集" },
            { data: "DiversityTitle",title: "分集名称" },
            { data: "DiversityPlayCount",title: "播放次数" }
      
     ],
            columnDefs: [

            {
                    targets:5,
                    data: null,
                    title: "操作",
                    render: function (data, type, row, meta) {

                         var href = '';
                      
                          href += "&nbsp;  <a href='javascript:void(0);' onclick=goPlayer("
                              + row.Id
                              + ")>";
                          href += "<i  title='预览' class='fa fa-play-circle-o fa-lg'></i></a>";
                        
                      
                      return href;

                    }
                }
             ,
                {
                    targets:6,
                    data: null,
                    title: "操作",
                    render: function (data, type, row, meta) {

                        var href = '';
                        
                             href += "&nbsp;  <a href='#/app/movie/program/dEdit/"+row.Id+"/"+row.ProgramId+"'>";
                          href += "<i  title='编辑' class='fa fa-edit fa-lg'></i></a>";
                          
                          href += "&nbsp;  <a href='javascript:void(0);' onclick=goDelete("
                              + row.Id
                              + ")>";
                          href += "<i  title='删除' class='fa fa-trash-o fa-lg'></i></a>";
                        
                      
                      return href;

                    }
                },
                 {
                    targets:7,
                    data: null,
                    title: "预览",
                    render: function (data, type, row, meta) {

                        var href = '';
                      
                          href += "&nbsp;  <a href='javascript:void(0);' onclick=goPlayer("
                              + row.Id
                              + ")>";
                          href += "<i  title='预览' class='fa fa-play-circle-o fa-lg'></i></a>";
                        
                      
                      return href;

                    }
                }


            ],
     drawCallback: function( settings ) {
         

           },

           initComplete:function(data){

//选中行
 $('#myTable tbody').on( 'click', 'tr', function () {
          
        if ( $(this).hasClass('selected') ) {
            $(this).removeClass('selected');
        }
        else {
            table.$('tr.selected').removeClass('selected');
            $(this).addClass('selected');
        }
        
    } );

//全选、反选
$('#allChecked').on('click' , function(){
  console.log(this.checked);
  var boxes = document.getElementsByName("ids");
    for(i=0;i<boxes.length;i++){
            boxes[i].checked = this.checked;
    }
    var optIds ='';
    if(this.checked){
      $("input[name='ids']:checkbox:checked").each(function(){ 
      optIds+=$(this).val() +',';
       });
    }else{
  optIds='';
      }
      if(''!=optIds){
        optIds = optIds.substring(0,optIds.length-1);
      }
      $('#optIds').val(optIds);
});




           },
            
     
            Paginate: true, 
           language:{
               url: 'vendor/jquery/datatables/Chinese.json'
          }

    });

});  




var playUrl = "";
function goPlayer(id){
  alert(id);
          //通过数据Id 得到文件ID
         var fileInfoUrl = API_URL+"program_diversity?query=delflag:0,Id:"+id;
          var formData =  MY_ASYNC_AJAX(fileInfoUrl)[0];
          console.log(formData);
          var fileId = formData.DiversityUuid;
          console.log("fileId:"+formData.DiversityUuid);
 
          //通过文件ID 得到播放地址Id
          var getPlayUrl = API_URL+"load_balancer/vod_play_url?FileUuid="+fileId;
          var playInfo =  MY_ASYNC_AJAX(getPlayUrl)[0];
            
           playUrl = playInfo.Url;
          if(undefined==playUrl||playUrl==''){
             top.layer.msg('暂时没有播放数据', {icon: 6});
              return false;
          }

  top.layer.open({
        type: 1,
        title: '',
        fix: false,
        shadeClose: false,
        anim: 4,
        move: true,
        area: ['600px', '400px'],
        content:"<div id='diversityVideo'><\/div>"
        ,success:function(){

            var flashvars={
              f:playUrl,
              c:0
            };
          doPlayVideo(flashvars);
        }
       
      });

}
function doPlayVideo(flashvars){
      
      var params={bgcolor:'#FFF',allowFullScreen:true,allowScriptAccess:'always',wmode:'transparent'};
      CKobject.embedSWF('vendor/jquery/ckplayer6.8/ckplayer/ckplayer.swf','diversityVideo','ckplayer_a1','600','400',flashvars,params);
    }



</script>







